package ncrnadb.cli;

import java.util.Map;
import java.util.TreeMap;

import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.impls.orient.OrientVertex;

import ncrnadb.core.EntityType;
import ncrnadb.core.ORDB;

public class EdgesCount {

	
	
	public static void main(String[] args){
		try{
			
			ORDB  ordb= new ORDB();
			ordb.open();
			
			Iterable<Edge> itEdges = ordb.graph.getEdgesOfClass("EInteraction");
			
			
			Integer ocount = 0;
			Map<EntityType, Integer> counts = new TreeMap<EntityType, Integer>();
			for(EntityType etype : EntityType.values()){
				counts.put(etype,  0);
			}
			
			int i = 0;
			EntityType e1,e2;
			for(Edge ed : itEdges){
				e1 = ordb.oRBioEntityClusters.get((((OrientVertex)ed.getVertex(Direction.OUT)).getIdentity().getClusterId())) ;
				e2 = ordb.oRBioEntityClusters.get((((OrientVertex)ed.getVertex(Direction.IN)).getIdentity().getClusterId())) ;
				
				
				
				if(e1==EntityType.NCRNA && e2==EntityType.NCRNA){
					counts.put(EntityType.NCRNA, counts.get(EntityType.NCRNA)+1);
				}
				else if(e1==EntityType.NCRNA){
					counts.put(e2, counts.get(e2)+1);
				}
				else if(e2==EntityType.NCRNA){
					counts.put(e1, counts.get(e1)+1);
				}
				else{
					System.out.println("# " +e1 + " "+ e2.type);
					ocount++;
				}
			
				System.out.println(i);
				i++;
			}
			
			
			
			for(Map.Entry<EntityType, Integer> en : counts.entrySet()){
				System.out.println(en.getKey() + " "+ en.getValue());
			}
			System.out.println("ocount "+ocount);
			
			
			
			ordb.close();
			
		}catch(Exception e){
			e.printStackTrace();
			System.out.println(e);
		}
	}
}
